<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        img {
            vertical-align: top;
            /*除去 图片底部有3像素空白缝隙的问题 */
        }

        .box {
            width: 490px;
            height: 170px;
            margin: 100px auto;
            border: 1px solid #ccc;
            padding: 5px;
        }

        .inner {
            width: 490px;
            height: 170px;
            background-color: pink;
            position: relative;
            overflow: hidden;
        }

        .inner ul {
            width: 1000%;
            position: absolute;
            left: 0;
            top: 0;
        }

        .inner ul li {
            float: left;
        }

        .square {
            position: absolute;
            right: 10px;
            bottom: 10px;
        }

        .square span {
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 1px solid #ccc;
            background-color: #fff;
            text-align: center;
            line-height: 16px;
            margin: 0 3px;
            cursor: pointer;
        }

        .square span.current {
            background-color: darkorange;
            color: white;
        }
    </style>
</head>

<body>
    <div class="box" id="box">
        <div class="inner">
            <ul>
                <li>
                    <a href="#"><img src="images/01.jpg" alt="" /></a>
                </li>
                <li>
                    <a href="#"><img src="images/02.jpg" alt="" /></a>
                </li>
                <li>
                    <a href="#"><img src="images/03.jpg" alt="" /></a>
                </li>
                <li>
                    <a href="#"><img src="images/04.jpg" alt="" /></a>
                </li>
                <li>
                    <a href="#"><img src="images/05.jpg" alt="" /></a>
                </li>
            </ul>
            <div class="square">
                <span class="current">1</span> <span>2</span> <span>3</span> <span>4</span> <span>5</span>
            </div>
        </div>
    </div>
    <script src="../d27/js/jquery.js"></script>
    <script>
        $.fn.extend({
            Swiper(){
                let self=this;
                this.find("span").click(function(){
                    $(this).addClass("current").siblings().removeClass("current");
                    $index=$(this).index();
                    self.find("ul").animate({left:-490*$index})
                })
            }
        })
        $(function(){
            $(".box").Swiper();
        })
    </script>
</body>
</html>
<!-- <script>
    // 类:将相同属性和行为提前成为一个独立类

     //类 对象

    // 对象的组成 == 属性 +方法


    class Swiper {
        constructor(el) {
            //整个大盒子
            this.el = document.querySelector(el);
            this.oUl = this.el.children[0].children[0];
            this.oSpans = this.el.children[0].children[1].children;
            this.clickHandler();
        }
        clickHandler() {
            var self = this;
            Array.from(this.oSpans).forEach((item, index) => {
                item.onclick = function () {
                    //这里的this,就是当前被点击的span
                    //想拿到Swiper 就需要在外面定义全局 self
                    //并且 self 等于 this
                    for (let i = 0; i < self.oSpans.length; i++) {
                        self.oSpans[i].className = i == index ? 'current' : ''
                    }
                    // this.className = 'current';
                    $.animate(self.oUl, {
                        left: -index * 490
                    })
                }
            })
        }
    }
    //实例化 new
    new Swiper("#box")

    // new Swiper("#box1")


</script> -->